/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Requests;

import java.io.Serializable;
import Utilities.Constants;
import Utilities.Functions;
import Utilities.PermissionsConstants;
import Utilities.Interfaces.SelfValidating;

/**
 * This is the superclass for all requests coming from the user interface and for
 * all requests being passed between internal components.
 *
 * @author Angel Sanadinov
 */
public abstract class RequestBean implements Serializable, SelfValidating
{
    private int requestorId;    //the id of the user that made the request
    private int serverId;       //the id of the server for which the request is valid
    private int requestedAction;//the id of the action that is requested

    /**
     * No-argument constructor. <br><br> 
     * All fields are set to their invalid values.
     *
     * @see Constants
     * @see PermissionsConstants#INVALID_ACTION
     */
    public RequestBean()
    {
        this(Constants.INVALID_USER_ID, Constants.INVALID_SERVER_ID, PermissionsConstants.INVALID_ACTION);
    }

    /**
     * Constructs a new request object, using the supplied data.
     *
     * @param requestorId the id of the user that requested the action
     * @param serverId the id of the server for which the request is valid
     * @param requstedAction the id of the action that is requested
     */
    public RequestBean(int requestorId, int serverId, int requstedAction)
    {
        this.requestorId = requestorId;
        this.serverId = serverId;
        this.requestedAction = requstedAction;
    }

    /**
     * Sets the id of the user that requested the action.
     *
     * @param requestorId the id of the user
     */
    public void setRequestorId(int requestorId)
    {
        this.requestorId = requestorId;
    }

    /**
     * Sets the id of the server for which the action is valid.
     *
     * @param serverId the server id
     */
    public void setServerId(int serverId)
    {
        this.serverId = serverId;
    }

    /**
     * Sets the id of the requested action.
     *
     * @param requestedAction request id
     */
    public void setRequestedAction(int requestedAction)
    {
        this.requestedAction = requestedAction;
    }

    /**
     * Retrieves the id of the user that requested the action.
     *
     * @return the requestor id
     */
    public int getRequestorId()
    {
        return requestorId;
    }

    /**
     * Retrieves the id of the server for which the action is valid.
     *
     * @return the server id
     */
    public int getServerId()
    {
        return serverId;
    }

    /**
     * Retrieves the id of the requested action.
     *
     * @return the action id
     */
    public int getRequestedAction()
    {
        return requestedAction;
    }

    /**
     * Checks if the id of the requestor is valid.
     *
     * @return <code>true</code> if the id is valid or <code>false</code> otherwise
     */
    protected boolean isRequestorIdValid()
    {
        return Functions.isUserIdValid(requestorId);
    }

    /**
     * Checks if the id of the server is valid.
     *
     * @return <code>true</code> if the id is valid or <code>false</code> otherwise
     */
    protected boolean isServerIdValid()
    {
        return Functions.isServerIdValid(serverId);
    }

    /**
     * Checks if the action id is valid.
     *
     * @return <code>true</code> if the action id is valid or <code>false</code>
     *         otherwise
     */
    protected boolean isRequestedActionValid()
    {
        if(requestedAction > PermissionsConstants.INVALID_ACTION)
            return true;
        else
            return false;
    }
}
